package com.dq.controller.user;

import com.dq.controller.in.user.WxUserQuery;
import com.dq.domain.sys.user.user.centre.UserLable;
import com.dq.exception.customException.AdminException;
import com.dq.service.AllService;
import com.dq.vo.ListDataVo;
import com.dq.vo.Vo;
import com.dq.vo.baseVo.VO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * @author cf
 */

@RestController
@RequestMapping("/sys/userLable/")
@Api(description = "顾客标签")
public class SysUserLableController extends AllService {


    /**
     * 所有用户标签, 区别于 技师标签
     */
    @PostMapping("list")
    @ApiOperation("所有顾客的标签, 不分页")
    public Vo customerList(@RequestBody WxUserQuery wxUserQuery)throws AdminException {
        List<UserLable> list = userLableRepository.findByDeletedFalseAndType(UserLable.LableType.one);
        return new ListDataVo((List<UserLable.Vo>) VO.toVOCollection(list));
    }

    /**
     * 已经存在直接返回, 否则添加
     * @param userLable
     * @return
     * @throws AdminException
     */
    @PostMapping("add")
    @ApiOperation("添加顾客标签/技师标签; [ type: one(顾客),two(技师)]")
    public Vo add(@Valid @RequestBody UserLable userLable)throws AdminException {
        UserLable get = userLableRepository.findByDeletedFalseAndNameAndType(userLable.getName(), userLable.getType());
        if(get == null) {
            get = userLableService.save(userLable);
        }


        return new Vo(get.toVO());
    }

}
